import socketserver

class MyTCPHandler(socketserver.BaseRequestHandler):
    '''
    定义一个类继承父类
    '''
    def handle(self):
        '''
        重写handle方法
        :return:
        '''
        while True:
            try:
                self.data = self.request.recv(1024).strip()
                print('{} wrote:'.format(self.client_address[0]))
                print(self.data)
                self.request.send(self.data.upper())
            except ConnectionResetError as e:
                print('err', e)
                break

if __name__ == '__main__':
    HOST, PORT = 'localhost', 9999

    server = socketserver.ThreadingTCPServer((HOST,PORT), MyTCPHandler)    #ThreadingTCPServer就是多线程
    server.serve_forever()